<?php

class Home_Model extends Model
{
	public function __construct()
	{
		parent::Model();
		
		// open the database
		$this->load->database();
	}

	function get_item_information($id)
	{
		$result = $this->db->query('SELECT item_id, item_name, category, title, description
									FROM item 
									WHERE item_id = \''.$id.'\'');

		return $result->result();
	}
/*	
	function search_item($category)
	{
		$result = $this->db->query('SELECT item_id, item_name, category, title, description
							FROM item 
							WHERE category like \'%'.$category.'%\'');
		
		return $result->result();
	}
*/
	function search_item($filename,$category)
	{
		$id=0;

		// finding the id
		if(strcmp($category," ")==0)
		{
			$result = $this->db->query('SELECT item_id, item_name, category, title, description
								FROM item 
								WHERE item_name like \'%'.$filename.'%\'' );
		}		
		else if((strcmp($category," ")!=0) && (strcmp($filename,"")!=0))
		{
			$result = $this->db->query('SELECT item_id, item_name, category, title, description
								FROM item 
								WHERE item_name like \'%'.$filename.'%\' AND  category like \'%'.$category.'%\'');
		}
		else if((strcmp($category," ")!=0) && (strcmp($filename,"")==0))
		{
			$result = $this->db->query('SELECT item_id, item_name, category, title, description
								FROM item 
								WHERE category like \'%'.$category.'%\'');
		}
		
		return $result->result();
	}

	
	function get_item_images($itemID)
	{
		$result = $this->db->query('SELECT image_id, filename, category, caption, item_id
									FROM file_info 
									WHERE item_id = \''.$itemID.'\'');
		
		return $result->result();
	}

}
?>